package problems.contest;

import java.util.HashMap;

/**
 * <p></p>
 *
 * @author habitplus
 * @since 10:51, 2023/1/15
 */
public class WCT328 {

    /**
     * T3|6293. 统计好子数组的数目
     * <p></p>
     */
    public long countGood(int[] nums, int k) {
        long ans = 0;
        int l = 0;
        HashMap<Integer, Integer> cntMap = new HashMap<>();
        int cnt;
        int pair = 0;
        int n = nums.length;
        for (int r = 0; r < n; ++r) {
            cnt = cntMap.getOrDefault(nums[r], 0);
            pair += cnt;

            if (pair >= k) {
                // 子数组[l, r] 已经满足条件
                ans += (n - r);
                while (l <= r) {
                    cntMap.getOrDefault(nums[l], 0);
                }
            }
        }


        return ans;
    }
}
